<?php
namespace app\admin\controller;
use think\Db;

class Auth extends Main
{  
    /**
     * 权限列表
    */
    public function index()
    {
        $data = Db::name('role')->select();
        $this->assign('list', $data);
        return $this->fetch();
    }

    //添加权限
    public function add(){
        $request = $this->request;
        if($request->isPost()){
            $post     = $request->post();

            $db = Db::name('role')
                ->insert($post);

            $this->success('添加成功');

        }else{
            //获取全部方法
            $auth = Db::name('auth')->select();
            $this->assign('auth',$auth);
            return $this->fetch('add');
        }
    }

    //编辑权限
    public function edit($id){
        $request = $this->request;
        if($request->isPost()){
            $post     = $request->post();

            $db = Db::name('role')
                ->where('id',$post['id'])
                ->update($post);

            $this->success('修改成功');

        }else{
            //获取全部方法
            $auth = Db::name('auth')->select();
            $this->assign('auth',$auth);

            $data = Db::name('role')->where('id',$id)->find();
            $this->assign('data',$data);
            return $this->fetch('edit');
        }
    }
}
